package com.admin.business.venusProjectCommercialAuditRecord;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 商家审核记录表
 * @create: 2023-11-18 14:30:55
 **/
@Service("venusProjectCommercialAuditRecordService")
@Slf4j
public class VenusProjectCommercialAuditRecordService{

    @Resource
    VenusProjectCommercialAuditRecordDao venusProjectCommercialAuditRecordDao;

    /**
     * 添加商家审核记录表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - service_id:商户服务id
     *                   - commercial_id:商家id
     *                   - audit_user_id:审核人id
     *                   - audit_result:审核结果0审核成功、1审核失败'
     *                   - audit_opinion:审核意见
     *                   - create_date:创建时间
     *                   - create_user_id:创建人
     *                   - audit_user_name:审核人姓名
     *                   - audit_type:审核类型0.商家认证1.商家服务上架
     * @return
     * @author liuzir
     * @create: 2023-11-18 14:30:55
     */
    @OpenApi
    public Return addVenusProjectCommercialAuditRecord(CDO cdoRequest) {
        venusProjectCommercialAuditRecordDao.addVenusProjectCommercialAuditRecord(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新商家审核记录表数据
     *
     * @param cdoRequest - id:主键
     *                   - service_id:商户服务id
     *                   - commercial_id:商家id
     *                   - audit_user_id:审核人id
     *                   - audit_result:审核结果0审核成功、1审核失败'
     *                   - audit_opinion:审核意见
     *                   - create_date:创建时间
     *                   - create_user_id:创建人
     *                   - audit_user_name:审核人姓名
     *                   - audit_type:审核类型0.商家认证1.商家服务上架
     * @return
     * @author liuzir
     * @create: 2023-11-18 14:30:55
     */
    @OpenApi
    public Return updateVenusProjectCommercialAuditRecordById(CDO cdoRequest) {
        venusProjectCommercialAuditRecordDao.updateVenusProjectCommercialAuditRecordById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除商家审核记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author liuzir
     * @create: 2023-11-18 14:30:55
     */
    @OpenApi
    public Return deleteVenusProjectCommercialAuditRecordById(CDO cdoRequest){
        int count = venusProjectCommercialAuditRecordDao.deleteVenusProjectCommercialAuditRecordById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除商家审核记录表数据
     *
     * @param cdoRequest
     * @return
     * @author liuzir
     * @create: 2023-11-18 14:30:55
     */
    @OpenApi
    public Return deleteVenusProjectCommercialAuditRecord(CDO cdoRequest) {
        int count = venusProjectCommercialAuditRecordDao.deleteVenusProjectCommercialAuditRecord(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取商家审核记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author liuzir
     * @create: 2023-11-18 14:30:55
     */
    @OpenApi
    public Return getVenusProjectCommercialAuditRecordById(CDO cdoRequest) {
        CDO cdoMapperResult = venusProjectCommercialAuditRecordDao.getVenusProjectCommercialAuditRecordById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取商家审核记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author liuzir
     * @create: 2023-11-18 14:30:55
     */
    @OpenApi
    public Return getVenusProjectCommercialAuditRecordListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusProjectCommercialAuditRecordDao.getVenusProjectCommercialAuditRecordListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusProjectCommercialAuditRecordDao.getVenusProjectCommercialAuditRecordCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取商家审核记录表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author liuzir
     * @create: 2023-11-18 14:30:55
     */
    @OpenApi
    public Return getVenusProjectCommercialAuditRecordListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusProjectCommercialAuditRecordDao.getVenusProjectCommercialAuditRecordListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusProjectCommercialAuditRecordDao.getVenusProjectCommercialAuditRecordCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
